@extends('admin.adminbase')
@section('content')
    <section class="hbox stretch">
        @include("admin.public.left")
        <aside>
            <section class="vbox">
                <header class="header bg-white b-b clearfix">
                    <form class="talbe-search" method="get" action="{{url('admin/banner')}}">
                        <div class="row m-t-sm">
                            <div class="col-sm-5 m-b-xs">
								<a role="button" class="btn btn-sm btn-primary" title="添加Banner" href="{{url("admin/banner/create")}}">添加Banner
									<i class="glyphicon glyphicon-plus"></i>
								</a>
							</div>

                            <div class="col-sm-3">
                                <select class="form-control input-sm" name="position">
                                    <option value="0" selected=""> 选择展示区域</option>
                                    <?php
                                    $positionList = \App\Http\Util\BannerPosition::getList();
                                    ?>
                                    @foreach($positionList as $position)
                                        <option value="{{ $position['value'] }}" @if( old('position') == $position['value']) selected="selected" @endif >{{ $position['label'] }}</option>
                                    @endforeach
                                </select>
                            </div>

                            <div class="col-sm-2">
                                <select class="form-control input-sm" name="status">
                                    <option value="0" selected=""> 选择状态</option>
                                    <?php
                                    $statusList = \App\Http\Util\Status::getList();
                                    ?>
                                    @foreach($statusList as $status)
                                        <option value="{{ $status['value'] }}"  @if( old('status') == $status['value']) selected="selected" @endif> {{ $status['label'] }}</option>
                                    @endforeach
                                </select>
                            </div>
                            {!! csrf_field() !!}
                            <button class="btn btn-sm btn-default" type="submit" title="搜索">
                                <i class="glyphicon glyphicon-search"></i> 搜索
                            </button>
                        </div>
                    </form>
                </header>

                <section class="scrollable  wrapper w-f">
                    <section class="panel panel-default">
                        <div class="table-responsive">
                            <table class="table table-hover m-b-none entity-view" data-path="/attendance/count/countDetail/id/{0}">
                                <thead>
                                <tr>
                                    <th style="text-align: center;">序号</th>
                                    <th style="text-align: center;">缩略图</th>
                                    <th style="text-align: center;">展示区域</th>
                                    <th style="text-align: center;">跳转链接</th>
                                    <th style="text-align: center;">状态</th>
                                    <th style="text-align: center;">创建时间</th>
                                    <th style="text-align: center;">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                    @foreach ($res as $k=>$v)
                                    <tr>
                                        <td style="text-align: center;">{{$limit*($res->currentPage()-1)+$k+1}}</td>
                                        <td style="text-align: center;"><img src="{{ config('config.picHostPrefix').$v->small_img }}" width="80px" height="40px"></td>
                                        <td style="text-align: center;">{{ \App\Http\Util\BannerPosition::getLabel( $v->position) }}</td>
                                        <td style="text-align: center;">{{ $v->link_url }}</td>
                                        <td style="text-align: center;" class="status">{{ \App\Http\Util\Status::getLabel($v->status) }}</td>
                                        <td style="text-align: center;">{{ \App\Http\Util\TimeHelper::formatDate($v->created_at) }}</td>

                                        <td style="text-align: center">
                                            <a href="{{ url('admin/banner/edit/'.$v->id) }}" class="label label-success">编辑</a>
                                            <a data-back="{{ url('admin/banner/delete/'.$v->id)}}"  class="del label label-danger">删除</a>
                                            <a data-id="{{$v->id}}" data-able="{{$v->status}}" class="label label-info able">@if($v->status == 1)禁用@else启用@endif</a>
                                        </td>
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    </section>
                    <div style="text-align: center">{!! $res->appends($_GET)->render() !!}</div>
                </section>

            </section>
        </aside>
    </section>

@endsection

@section('addscript')
	<script>
		$(function(){
            $(".del").click(function(){
                var url=$(this).attr("data-back");

                layer.confirm('您确定删除吗？', {
                    btn: ['确认','取消'] //按钮
                }, function(){
                    $.post(url,{},function(data){
                        if(data){
                            layer.alert("删除成功！",function(){
                                location.reload();
                            });
                        }else{
                            layer.alert(data.msg)
                        }
                    });
                }, function(){

                })
            })

            $(".able").click(function(){
                var id=$(this).data("id");
                var able = $(this).data("able");
                if(able==1) {
                    able=2;
                } else {
                    able=1;
                }
                var mythis = $(this);
                $.ajax({
                    'url':"/admin/banner/able/"+id+"/"+able,
                    'type':"get",
                    'dataType':'json',
                    'success':function(data){
                        if(data.success){
                            mythis.parent().find('.able').text(data.msg);
                            mythis.parent().find('.able').data('able',data.data);
                            if (data.data==1) {
                                var m ="启用"
                            } else {
                                var m ="禁用"
                            }
                            mythis.parent().parent().find('.status').text(m);
                        }else{
                            layer.alert(data.msg)
                        }
                    }
                })
            })
		});
	</script>
@endsection
